/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wli.web.jsf.bean;

import java.util.Iterator;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import wli.web.db.HibernateUtil;
import wli.web.db.Vocabulary;
import wli.web.db.VocabularyHelper;

/**
 *
 * @author liw
 */
@ManagedBean
@SessionScoped
public class VocabularyController {

    private VocabularyHelper vcHelper;
    private Session session;
    private List<Vocabulary> vocabularyList;

    /** Creates a new instance of VocabularyController */
    public VocabularyController() {
        vcHelper = new VocabularyHelper();
    }

    public List<Vocabulary> getVocabularyList() {

        try {
            session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Vocabulary");
            //System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
            vocabularyList = q.list();
            /*
           Iterator <Vocabulary> it = vocabularyList.iterator();
           while (it.hasNext()) {
               System.out.println(it.next());
           }*/
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vocabularyList;
    }
    
    public String getTestJSF () {
        return "this is a test for JSF";
    }
}
